# 中介者模式
# 中介者模式是一种行为型设计模式，它通过一个中介对象来封装一系列对象之间的交互。

# 角色
# 中介者: 定义了对象之间的交互方式
# 具体中介者: 实现了中介者接口，负责对象之间的交互
# 同事类: 定义了对象之间的交互方式，但是不负责具体的交互
# 具体同事类: 实现了同事类接口，负责具体的交互

from abc import ABCMeta, abstractmethod
class Mediator(metaclass=ABCMeta):
    @abstractmethod
    def send(self, message, colleague):
        pass

class ConcreteMediator(Mediator):
    def __init__(self):
        self.colleague1 = None
        self.colleague2 = None

    def send(self, message, colleague):
        if colleague == self.colleague1:
            self.colleague2.notify(message)
        else:
            self.colleague1.notify(message)

class Colleague(metaclass=ABCMeta):
    def __init__(self, mediator):
        self.mediator = mediator

    @abstractmethod
    def send(self, message):
        pass

    @abstractmethod
    def notify(self, message):
        pass

class ConcreteColleague1(Colleague):
    def send(self, message):
        self.mediator.send(message, self)

    def notify(self, message):
        print("ConcreteColleague1 received message: " + message)

class ConcreteColleague2(Colleague):
    def send(self, message):
        self.mediator.send(message, self)

    def notify(self, message):
        print("ConcreteColleague2 received message: " + message)

if __name__ == "__main__":
    mediator = ConcreteMediator()
    colleague1 = ConcreteColleague1(mediator)
    colleague2 = ConcreteColleague2(mediator)
    mediator.colleague1 = colleague1
    mediator.colleague2 = colleague2
    colleague1.send("Hello, colleague2")
    colleague2.send("Hello, colleague1")
    # Output: ConcreteColleague2 received message: Hello, colleague1
    # ConcreteColleague1 received message: Hello, colleague2
    